package com.example.journalegocentrique;
import android.content.Context;
import 	android.database.sqlite.*;
import android.provider.BaseColumns;

public class MyOpenHelper extends SQLiteOpenHelper{
	private static final String DATABASE_NAME = "jedb.db";
	private static final int DATABASE_VERSION = 2;
	public static final String TABLEday = "tbDay";
	public static final String TABLEentry = "tbEntry";
	public static final String TABLEmood = "tbMood";
	public static final String DAY = "day";
	public static final String PHOTO = "photo";
	public static final String HOUR = "hour";
	public static final String MOOD = "mood";
	public static final String NOTE = "note";
	public static final String IDDAY = "idDay";
	public static final String POSITION = "position";
	public static final String PLACE = "place";
	public static final String VALUE = "value";



	public MyOpenHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		String sql1 = "create table " + TABLEday + "( " + BaseColumns._ID
				+ " integer primary key autoincrement, " + DAY
				+ " date, " + PHOTO + " text," + HOUR + " datetime);";
		
		String sql2 = "create table " + TABLEentry + "( " + BaseColumns._ID
				+ " integer primary key autoincrement, " + HOUR
				+ " datetime, " + MOOD + " integer, " + NOTE + " text, " + IDDAY + " integer, "+ POSITION +" text, " + PLACE + " text );";
		
		String sql3 = "create table " + TABLEmood + "( " + BaseColumns._ID
				+ " integer primary key autoincrement, " + MOOD
				+ " text, " + VALUE + " integer);";
		
		db.execSQL(sql1);
		db.execSQL(sql2);
		db.execSQL(sql3);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		String sql = null; 
		if (oldVersion == 2)
			sql = "alter table " + TABLEentry + " add " + PLACE + " text;";
		if (sql != null)
			db.execSQL(sql);
	}
	
	

}
